<!DOCTYPE html>
<html ng-app="demoApp">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Loading 加载动画 - ng-components-ui</title>
    <link rel="stylesheet" href="../dist/ng-components.css" />
    <style>
      * {
        box-sizing: border-box;
      }

      body {
        font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
        margin: 0;
        padding: 0;
        background: #f5f5f5;
      }

      .header {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
        padding: 30px 40px;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
      }

      .header h1 {
        margin: 0 0 10px 0;
        font-size: 32px;
      }

      .header p {
        margin: 0;
        opacity: 0.9;
        font-size: 16px;
      }

      .back-link {
        display: inline-block;
        margin-top: 15px;
        color: white;
        text-decoration: none;
        padding: 8px 16px;
        background: rgba(255, 255, 255, 0.2);
        border-radius: 4px;
        transition: background 0.2s;
      }

      .back-link:hover {
        background: rgba(255, 255, 255, 0.3);
      }

      .container {
        max-width: 1400px;
        margin: 0 auto;
        padding: 40px;
      }

      .demo-section {
        background: white;
        padding: 30px;
        border-radius: 8px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
        margin-bottom: 30px;
      }

      .demo-section h2 {
        margin: 0 0 20px 0;
        color: #333;
        font-size: 20px;
        border-bottom: 2px solid #667eea;
        padding-bottom: 10px;
      }

      .demo-section h3 {
        margin: 20px 0 15px 0;
        color: #555;
        font-size: 16px;
        font-weight: 600;
      }

      .demo-section p {
        color: #666;
        line-height: 1.6;
        margin: 0 0 15px 0;
      }

      .demo-actions {
        display: flex;
        gap: 15px;
        flex-wrap: wrap;
        margin: 20px 0;
      }

      .btn {
        padding: 10px 20px;
        border: none;
        border-radius: 6px;
        cursor: pointer;
        font-size: 14px;
        font-weight: 500;
        transition: all 0.2s;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
      }

      .btn:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
      }

      .btn-primary {
        background: #667eea;
        color: white;
      }

      .btn-success {
        background: #48bb78;
        color: white;
      }

      .btn-warning {
        background: #ed8936;
        color: white;
      }

      .btn-info {
        background: #4299e1;
        color: white;
      }

      .code-block {
        background: #f7fafc;
        border: 1px solid #e2e8f0;
        border-radius: 4px;
        padding: 15px;
        margin: 10px 0;
        font-family: "Monaco", "Menlo", "Ubuntu Mono", monospace;
        font-size: 12px;
        overflow-x: auto;
      }

      .code-block code {
        color: #2d3748;
      }

      .feature-list {
        background: #f7fafc;
        border-left: 4px solid #667eea;
        padding: 15px 20px;
        margin: 20px 0;
      }

      .feature-list ul {
        margin: 0;
        padding-left: 20px;
      }

      .feature-list li {
        color: #4a5568;
        margin: 8px 0;
        line-height: 1.6;
      }

      .demo-box {
        position: relative;
        border: 2px dashed #e2e8f0;
        border-radius: 8px;
        padding: 40px;
        text-align: center;
        background: #f7fafc;
        min-height: 200px;
        display: flex;
        align-items: center;
        justify-content: center;
        margin: 20px 0;
      }
    </style>
  </head>
  <body ng-controller="DemoController">
    <div class="header">
      <h1>Loading 加载动画组件</h1>
      <p>全屏加载遮罩，适用于异步操作场景</p>
      <a href="home.html" class="back-link">← 返回主页</a>
    </div>

    <div class="container">
      <div class="demo-section">
        <h2>Loading 加载动画 ($loading)</h2>

        <div class="feature-list">
          <strong>功能特性:</strong>
          <ul>
            <li>全屏遮罩式加载动画</li>
            <li>可自定义加载文本</li>
            <li>可自定义颜色和大小</li>
            <li>优雅的淡入淡出动画</li>
            <li>适用于 API 请求、数据加载等场景</li>
          </ul>
        </div>

        <h3>1. 基本用法</h3>
        <p>使用 $loading 服务显示和隐藏加载动画</p>
        <div class="demo-actions">
          <button class="btn btn-primary" ng-click="showBasicLoading()">
            显示加载动画（2秒）
          </button>
        </div>

        <div class="code-block">
          <code>
// 显示 loading<br>
$loading.show();<br>
<br>
// 隐藏 loading<br>
$loading.hide();
          </code>
        </div>

        <h3>2. 带文本提示</h3>
        <p>通过配置对象设置加载文本</p>
        <div class="demo-actions">
          <button class="btn btn-success" ng-click="showLoadingWithText()">
            带文本的加载（3秒）
          </button>
        </div>

        <div class="code-block">
          <code>
$loading.show({<br>
&nbsp;&nbsp;text: '加载中...'<br>
});
          </code>
        </div>

        <h3>3. 不同大小</h3>
        <p>可设置 small、medium、large 三种大小</p>
        <div class="demo-actions">
          <button class="btn btn-info" ng-click="showSmallLoading()">
            小尺寸
          </button>
          <button class="btn btn-info" ng-click="showMediumLoading()">
            中尺寸（默认）
          </button>
          <button class="btn btn-info" ng-click="showLargeLoading()">
            大尺寸
          </button>
        </div>

        <div class="code-block">
          <code>
// 小尺寸<br>
$loading.show({ size: 'small', text: '加载中...' });<br>
<br>
// 中尺寸（默认）<br>
$loading.show({ size: 'medium', text: '加载中...' });<br>
<br>
// 大尺寸<br>
$loading.show({ size: 'large', text: '加载中...' });
          </code>
        </div>

        <h3>4. 自定义颜色</h3>
        <div class="demo-actions">
          <button class="btn btn-warning" ng-click="showCustomColor()">
            自定义颜色（2秒）
          </button>
        </div>

        <div class="code-block">
          <code>
$loading.show({<br>
&nbsp;&nbsp;text: '自定义颜色',<br>
&nbsp;&nbsp;color: '#f56565'<br>
});
          </code>
        </div>

        <h3>5. 实际应用场景</h3>
        <p>模拟 API 请求场景</p>
        <div class="demo-actions">
          <button class="btn btn-success" ng-click="simulateApiCall()">
            模拟 API 请求（3秒）
          </button>
          <button class="btn btn-warning" ng-click="simulateDataLoad()">
            模拟数据加载（2秒）
          </button>
          <button class="btn btn-info" ng-click="simulateFileUpload()">
            模拟文件上传（4秒）
          </button>
        </div>

        <div class="code-block">
          <code>
// 模拟 API 请求<br>
function simulateApiCall() {<br>
&nbsp;&nbsp;$loading.show({ text: '请求中...' });<br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;$timeout(function() {<br>
&nbsp;&nbsp;&nbsp;&nbsp;$loading.hide();<br>
&nbsp;&nbsp;&nbsp;&nbsp;ngToast.success('请求成功！');<br>
&nbsp;&nbsp;}, 3000);<br>
}
          </code>
        </div>

        <h3>6. 指令式用法</h3>
        <p>使用 ng-loading 指令在元素上显示局部加载</p>
        <div class="demo-box" ng-loading="isLocalLoading" loading-text="加载数据中...">
          <div ng-if="!isLocalLoading">
            <p>这里是内容区域</p>
            <button class="btn btn-primary" ng-click="showLocalLoading()">
              显示局部加载（3秒）
            </button>
          </div>
        </div>

        <div class="code-block">
          <code>
&lt;div ng-loading="isLoading" loading-text="加载中..."&gt;<br>
&nbsp;&nbsp;内容区域<br>
&lt;/div&gt;<br>
<br>
// Controller<br>
$scope.isLoading = true;<br>
$timeout(function() {<br>
&nbsp;&nbsp;$scope.isLoading = false;<br>
}, 2000);
          </code>
        </div>
      </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/angular@1.8.3/angular.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/angular-strap@2.3.12/dist/angular-strap.min.js"></script>
    <script src="../dist/ng-components.js"></script>
    <script>
      angular
        .module("demoApp", ["ngComponents"])
        .controller("DemoController", function ($scope, $loading, $timeout, ngToast) {
          $scope.isLocalLoading = false;

          // 基本用法
          $scope.showBasicLoading = function () {
            $loading.show();
            $timeout(function () {
              $loading.hide();
            }, 2000);
          };

          // 带文本
          $scope.showLoadingWithText = function () {
            $loading.show({
              text: "加载中..."
            });
            $timeout(function () {
              $loading.hide();
            }, 3000);
          };

          // 不同大小
          $scope.showSmallLoading = function () {
            $loading.show({
              size: "small",
              text: "小尺寸加载"
            });
            $timeout(function () {
              $loading.hide();
            }, 2000);
          };

          $scope.showMediumLoading = function () {
            $loading.show({
              size: "medium",
              text: "中尺寸加载"
            });
            $timeout(function () {
              $loading.hide();
            }, 2000);
          };

          $scope.showLargeLoading = function () {
            $loading.show({
              size: "large",
              text: "大尺寸加载"
            });
            $timeout(function () {
              $loading.hide();
            }, 2000);
          };

          // 自定义颜色
          $scope.showCustomColor = function () {
            $loading.show({
              text: "自定义颜色",
              color: "#f56565"
            });
            $timeout(function () {
              $loading.hide();
            }, 2000);
          };

          // 实际应用场景
          $scope.simulateApiCall = function () {
            $loading.show({ text: "请求中..." });

            $timeout(function () {
              $loading.hide();
              ngToast.success("API 请求成功！");
            }, 3000);
          };

          $scope.simulateDataLoad = function () {
            $loading.show({ text: "加载数据..." });

            $timeout(function () {
              $loading.hide();
              ngToast.info("数据加载完成");
            }, 2000);
          };

          $scope.simulateFileUpload = function () {
            $loading.show({
              text: "上传文件中...",
              size: "large"
            });

            $timeout(function () {
              $loading.hide();
              ngToast.success("文件上传成功！");
            }, 4000);
          };

          // 局部加载
          $scope.showLocalLoading = function () {
            $scope.isLocalLoading = true;
            $timeout(function () {
              $scope.isLocalLoading = false;
            }, 3000);
          };
        });
    </script>
  </body>
</html>
